<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
    }

    .adBox {
      width: 300px;
      height: 400px;
      background-color: #6ff;
      position: fixed;
      right: 5px;
      bottom: 5px;
    }

    .close {
      padding: 5px;
      position: absolute;
      right: 0;
      top: 0;
      color: #fff;
      background-color: #f00;
    }
  </style>
</head>

<body>
  <div class="adBox">
    <div class="close">X</div>
  </div>
</body>
<script>

  // 事件冒泡 是浏览器默认的事件传播机制 

  // 需求: closeBtn事件触发之后 不在向外层冒泡(阻止谁 就在谁上写)
  // 阻止事件冒泡 (阻止事件向外层传播 )

  // 常规浏览器
  // e.stopPropagation();

  // IE低版本
  // e.cancelBubble = true;   //是否阻止冒泡 (默认false:不阻止  true:阻止)

  // 兼容写法
  // if(e.stopPropagation){
  //     e.stopPropagation();
  // }else{
  //     e.cancelBubble = true;
  // }


  var adBox = document.querySelector(".adBox");
  var closeBtn = document.querySelector(".close");

  // 冒泡
  // mousedown:   closeBtn => adBox(有 => 触发)
  // click:       closeBtn => adBox(没有)

  adBox.onmousedown = function () {
    console.log("adBox被点击:mousedown");
    location.href = "https://www.baidu.com";
  }
  closeBtn.onclick = function (e) {
    var e = e || window.event;
    console.log(e);
    console.log("close被点击:click");
    adBox.style.display = "none";
  }

  closeBtn.onmousedown = function (e) {
    var e = e || window.event;
    console.log(e);

    // 兼容写法
    if (e.stopPropagation) {
      e.stopPropagation();
    } else {
      e.cancelBubble = true;
    }
  }


</script>

</html>